package dao.impl;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import dao.UseDocRecordDao;
import po.record.UseDocRecord;

public class UseDocRecordDaoImpl implements UseDocRecordDao{
	private List<UseDocRecord> udrs;
	
	public UseDocRecordDaoImpl() {
		udrs = new LinkedList<>();
	}

	@Override
	public boolean insert(UseDocRecord t) {
		if(udrs.contains(t)) {
			return false;
		}
		return udrs.add(t);
	}

	@Override
	public boolean update(UseDocRecord t) {
		int index = udrs.indexOf(t);
		if(index == -1) {
			return false;
		}else {
			udrs.set(index, t);
			return true;
		}
	}

	@Override
	public boolean delete(int id) {
		Iterator<UseDocRecord> it = udrs.iterator();
		while(it.hasNext()) {
			UseDocRecord ud = it.next();
			if(ud.getUseId() == id) {
				it.remove();
				return true;
			}
		}
		return false;
	}

	@Override
	public UseDocRecord selectById(int id) {
		for(UseDocRecord u :udrs) {
			if(u.getUseId() == id) {
				return u;
			}
		}
		return null;
	}

	@Override
	public List<UseDocRecord> selectAll() {
		List<UseDocRecord> copy = new LinkedList<>();
		return copy;
	}

}
